﻿/**
*    Copyright (C) 2008  Chase Kernan 
*    chase.kernan@gmail.com
*
*    This program is free software: you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation, either version 3 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with this program.  If not, see <http://www.gnu.org/licenses/>.
* 
*/

package com.chasekernan.hxnova.componenteditor.details;

import com.chasekernan.hxnova.componenteditor.DetailsPanel;
import com.chasekernan.hxnova.core.components.Shield;
import org.aswing.JAdjuster;
import com.chasekernan.hxnova.componenteditor.ComponentEditorPanel;

class ShieldPanel extends DetailsPanel {
    
    private var strengthInput : JAdjuster;
    private var strengthArmorInput : JAdjuster;
    
    public function new() {
        super();
        
        strengthInput = DetailsPanel.createIntAdjuster(1, 10000);
        strengthArmorInput = DetailsPanel.createIntAdjuster(0, 10000);
        
        addRowHaxe(createLeftLabel("Strength"), strengthInput, null);
        addRowHaxe(createLeftLabel("Armor Strength"), strengthArmorInput, createRightLabel("(Optional)"));
        
        allInputs = [strengthInput, strengthArmorInput];
    }
    
    public override function loadFromComponent() {
        if (ComponentEditorPanel.INSTANCE.editedComponent == null) return;
        
        var shield = cast(ComponentEditorPanel.INSTANCE.editedComponent, Shield);
        
        strengthInput.setValue(shield.strength);
        strengthArmorInput.setValue(shield.strengthArmor);
    }
    
    public override function saveToComponent() {
        if (ComponentEditorPanel.INSTANCE.editedComponent == null) return;
        
        var shield = cast(ComponentEditorPanel.INSTANCE.editedComponent, Shield);
        
        shield.strength = strengthInput.getValue();
        shield.strengthArmor = strengthArmorInput.getValue();
    }
}